using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using IQIGame.Onigao.GameAOT;
using System;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    public class UIN_InteractOptionItem : UIBaseNode
    {
        private class UIB_InteractOptionItem
        {
            public IQIGame.Onigao.Framework.ExButton button { protected set; get; }
            public virtual void InitBinding(ObjectBinding __binding)
            {
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExButton>("button", out var __tbv0);
                this.button = __tbv0;
            }

            public virtual void StartBinding(GameObject __go)
            {
                var binding = __go.GetComponent<ObjectBinding>();
                if (binding != null)
                {
                    this.InitBinding(binding);
                }
            }
        }

        private UIB_InteractOptionItem ui;
        private Action<UIInteractOption.ResultType, int> _onClick;
        private UIInteractOption.ResultType _type;
        private int _index;

        protected override void BeforeInit()
        {
            ui = new UIB_InteractOptionItem();
            ui.StartBinding(gameObject);
        }

        protected override void OnInit()
        {
            ui.button.AddClickEvent(OnClickButton);
        }

        protected override void OnShow()
        {

        }

        protected override void OnHide()
        {

        }

        private void OnClickButton()
        {
            _onClick(_type, _index);
        }

        public void SetData(UIInteractOption.ResultType type, int index, string text, Action<UIInteractOption.ResultType, int> onClick)
        {
            this._type = type;
            this._index = index;
            ui.button.text = text;
            this._onClick = onClick;
        }

        protected override void OnDispose()
        {

        }
    }
}
